package 线程池案例;

/*import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
//线程池
class MyThreadPool {
    //阻塞队列存放任务
    BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
    //默认最大线程数为10
    private int vip = 10;
    //存放任务
    public void submit(Runnable task) throws InterruptedException {
        queue.put(task);
    }
    //创建vip个线程来执行任务
    public MyThreadPool() {
        for(int i = 0; i < vip; i++){
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    while(true){
                        try {
                            Runnable task = queue.take();
                            task.run();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            });
            thread.start();
        }
    }
}


public class Test {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool pool = new MyThreadPool();
        for(int i = 1; i <= 1000; i++){
            int f = i;
            pool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("当前第" + f +"个任务，执行线程：" + Thread.currentThread().getName());
                }
            });
        }

    }
}*/
